package com.eveno.demo.android.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.eveno.demo.android.R;
import com.eveno.demo.android.route.PageRouter;
import com.eveno.demo.android.utils.StatusBar;

import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;

public class MainActivity extends AppCompatActivity implements Button.OnClickListener{

    public static WeakReference<MainActivity> sRef;
    private Button nativePageButton;
    private Button flutterPageButton;
    private Button flutterFragmentButton;
    private Button webViewButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        sRef = new WeakReference<>(this);
        StatusBar.setStatusBarColor(this, R.color.white);
        setContentView(R.layout.activity_main);
        // 获取三个按钮
        nativePageButton = (Button)findViewById(R.id.openNativePage);
        flutterPageButton = (Button)findViewById(R.id.openFlutterPage);
        flutterFragmentButton = (Button)findViewById(R.id.openFlutterFragment);
        webViewButton = (Button)findViewById(R.id.webViewButton);


        // 为按钮绑定点击事件
        nativePageButton.setOnClickListener(this::onClick);
        flutterPageButton.setOnClickListener(this::onClick);
        flutterFragmentButton.setOnClickListener(this::onClick);
        webViewButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                System.out.println("点击唤起webview页面");
                startActivity(new Intent(MainActivity.this, com.eveno.demo.android.activity.DsBridgeActivity.class));
            }
        });
    }


    @Override
    public void onClick(View view) {
        Map params = new HashMap();
        params.put("test1","v_test1");
        params.put("test2","v_test2");
        if(view == nativePageButton){
            PageRouter.openPageByUrl(this, PageRouter.NATIVE_PAGE_URL, params);
        } else if(view == flutterPageButton){
            PageRouter.openPageByUrl(this, PageRouter.FLUTTER_PAGE_URL, params);
        } else if(view == flutterFragmentButton){
            PageRouter.openPageByUrl(this, PageRouter.FLUTTER_FRAGMENT_PAGE_URL,params);
        }
    }
}
